<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <head th:include="common :: header"></head>
    <style>
        .table-responsive {
            min-height: 0.01%;
            overflow-x: unset !important;
        }
    </style>
</head>

<body>
<!--Page content-->
<div id="page-content">
    <div class="row">
        <div class="col-xs-3">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">代码生成</h3>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" id="generateForm" th:action="@{${action}}">
                        <!--<div class="modal-header">-->
                            <!--<h4 class="modal-title"></h4>-->
                        <!--</div>-->
                        <div class="modal-body">
                            <!--查询 input-->
                            <div class="panel-body">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">表名前缀</label>
                                    <div class="col-sm-8">
                                        <input type="text" placeholder="表名前缀" id="tablePrefix" name="tablePrefix" value="t_" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">表名</label>
                                    <div class="col-sm-8">
                                        <input type="text" placeholder="表名" id="tableName" name="tableName" class="form-control"
                                           data-bv-notempty="true"
                                           data-bv-notempty-message="表名不能为空">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">包名</label>
                                    <div class="col-sm-8">
                                        <input type="text" placeholder="包名" id="packageName" name="packageName" value="com.extlight" class="form-control"
                                           data-bv-notempty="true"
                                           data-bv-notempty-message="包名不能为空">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">模块名称</label>
                                    <div class="col-sm-8">
                                        <input type="text" placeholder="模块名称" id="moduleName" name="moduleName" class="form-control"
                                           data-bv-notempty="true"
                                           data-bv-notempty-message="模块名称不能为空">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">作者</label>
                                    <div class="col-sm-8">
                                        <input type="text" placeholder="作者" id="author" name="author" class="form-control" th:value="${session.currentUser.username}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">邮箱地址</label>
                                    <div class="col-sm-8">
                                        <input type="text" placeholder="邮箱地址" id="email" name="email" class="form-control" th:value="${session.currentUser.email}">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button class="btn btn-warning" type="reset">重置</button>
                            <button class="btn btn-primary" type="submit">生成</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-xs-9">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">数据库表列表</h3>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table id="listTable"
                               data-toolbar="#toolbar"
                               data-search="true"
                               data-search-on-enter-key="true"
                               data-detail-view="true"
                               data-minimum-count-columns="2"
                               data-classes="table table-hover table-borderless"
                               data-sort-order="desc">
                            <thead>
                                <tr>
                                    <th data-align="center" data-checkbox="true"></th>
                                    <th data-formatter="numFormatter">序号</th>
                                    <th data-field="tableSchema">库名</th>
                                    <th data-field="tableName">表名</th>
                                    <th data-field="engine">存储引擎</th>
                                    <th data-field="tableComment">备注</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--End page content-->
<div th:include="common :: script"></div>
<script type="text/javascript" th:inline="javascript" >

    function numFormatter(value, row, index) {
        return index + 1;
    }

    $(function() {
        /**
         *  init 方法中可传入的参数:
         *    id: "listTable",              // table id
         *    baseUrl: "",                  // 基础路径
         *    addUIUrl: "saveUI.html",       // 新增页面地址
         *    editUIUrl: "updateUI.html",     // 编辑页面地址
         *    deleteUrl: "delete.json",     // 删除地址
         *    listUrl: "list.json",         // 列表地址
         *    detailUIUrl: "detailUI.html", // 详情地址
         *    queryFormId: "queryForm",     // 搜索框表单 id
         *    columns：[],                  // bootstrap-table cell 参数，页面默认使用内嵌方式设置数据
         *    pagination：true              // 是否分页
         */
        var prefix = [[${prefix}]];
        $.freedom.ui.table.init({
            baseUrl: prefix,
            pagination: false  // 分页
        });

        var $table = $("#" + $.freedom.ui.table.options.id);
        $table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function () {
            var rows = $table.bootstrapTable('getSelections');
            var checkedArr = [];
            for (var i = 0, len = rows.length; i < len; i++) {
                checkedArr.push(rows[i].tableName);
            }

            $("#tableName").val(checkedArr.join(","));
        });

        // 生成代码事件
        var $form = $(document.getElementsByTagName("form")[0]);
        $form.bootstrapValidator().on('success.form.bv', function(e) {
            e.preventDefault();
            var url = $form.attr("action") + "?" + $form.serialize();
            $.freedom.action.download(url);
        });
    });

</script>
</body>
</html>
